<?php defined('SYSPATH') or die('No direct access allowed.');

class logunit
{
    private static $logModel = 'log';
    
    private static $errorlogModel = 'log';
    
    public static function log($userId = 1,$action = '',$content = '',$sql = '')
    {
    	if (!($model = project::config('libconfig')->logSqlTable)){
    		$model = self::$logModel; 
    	}
        $log = ORM::factory($model);

        $data = array(
        	'userId'=>$userId,
        	'action'=>$action,
        	'content'=>$content,
        	'sql'=>$sql
        );
        if ($log->values($data)->check())
        {
            return $log->save()->id;
        }
        return false;
    }

    //
    public static function errorlog($userId = 1,$errorinf = '',$content = '')
    {
    	if (!($model = project::config('libconfig')->errorlogSqlTable)){
    		$model = self::$errorlogModel; 
    	}
        $errorlog = ORM::factory($model);

        $data = array(
        	'userId'=>$userId,
            'controller'=>Kohana_Request::current()->controller(),
            'action'=>Kohana_Request::current()->action(),
            'errorinf'=>$errorinf,
        	'content'=>$content
        );
        //var_dump($data);
        if ($errorlog->values($data)->check())
        {
            return $errorlog->save()->id;
        }
        return false;
    }
}
